package com.sjm.learn.lock;

/**
 * @Description:案例2
 * @Author：shenjm25081
 * @Date：10:40 2019-2-22
 */
public class SynchronizedDemo4 implements Runnable{


    private static int count = 0;

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(new SynchronizedDemo4()); thread.start();
        } try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } System.out.println("result: " + count);
    }

    @Override
    public void run() {
        synchronized (SynchronizedDemo4.class) {
            for (int i = 0; i < 1000000; i++){
                count++;
            }
        }
    }
}
